package com.yuantong.xyerp.core.provider.dao;

import com.yuantong.xyerp.core.api.model.Category;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by Jianguo.Yin on 2021-08-03.
 */
public interface CategoryMapper {

    //todo: 去掉 codeList 会报错
    /**
     * 根据 codeList 找到对应品类名
     * @param codeList
     * @return
     */
    @Select({"<script> " +
            "SELECT c.name FROM t_category c WHERE 1=1 AND c.status = 1 " +
            "<if test=\"codeList != null and codeList.size() > 0\"> " +
            "AND c.code IN " +
            "<foreach collection=\"codeList\" item=\"code\" open=\"(\" close=\")\" separator=\",\"> " +
            "#{code} " +
            "</foreach> " +
            "</if> " +
            "ORDER BY create_time DESC " +
            "</script>"})
    List<String> findByCategoryCodeList(@Param("codeList") List<String> codeList);

    /**
     * 这里主要想得到 所有code与name
     * @return 返回所有品类
     */
    @Select({"<script> " +
            "SELECT DISTINCT c.* FROM t_category c WHERE 1=1 AND c.status = 1 " +
            "ORDER BY create_time DESC " +
            "</script>"})
    @ResultMap("BaseResultMap")
    List<Category> findByFuzzy();
}
